﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using University.Workshop.Presenters.Square.Register;
using Microsoft.Win32;

namespace University.Workshop.Presentation.Square.Register
{
    /// <summary>
    /// Interaction logic for PageFirstStepRegisterSquare.xaml
    /// </summary>
    public partial class PageFirstStepRegisterSquare : Page,IFirstStepForRegisterSquare
    {
        private PresenterRegisterNewSquare pInternal;
        private PresenterFirstStepForRegisterSquare pFirstStepForRegisterSquare;

        public PageFirstStepRegisterSquare(PresenterRegisterNewSquare pExternal)
        {
            InitializeComponent();
            pInternal=pExternal;
            pFirstStepForRegisterSquare = new PresenterFirstStepForRegisterSquare(this);
            App.Current.MainWindow.Title = "UIRegistrarManzano";
        }

        private void SearchCroquisBtn_Click(object sender, RoutedEventArgs e)
        {
            pFirstStepForRegisterSquare.LoadImage();
        }

        public string UbicationCroquisSquare
        {
            get
            {
                OpenFileDialog op = new OpenFileDialog();
            op.Title = "Buscar Croquis";
            op.Filter = "All supported graphics|*.jpg;*.jpeg;*.png|" +
                "JPEG (*.jpg;*.jpeg)|*.jpg;*.jpeg|" +
                "Portable Network Graphic (*.png)|*.png";
            if (op.ShowDialog() == true)
            {
                return op.InitialDirectory + op.FileName;
            }
            return UbicationCroquisSquareToRegister;
            
            }
            
            set
            {
                if (!string.IsNullOrWhiteSpace(value))
                    if (File.Exists(value))
                    {
                CroquisUbicationTxBx.Text = value;
                        BitmapImage image = new BitmapImage();
                        using (FileStream stream = File.OpenRead(value))
                        {
                            image.BeginInit();
                            image.StreamSource = stream;
                            image.CacheOption = BitmapCacheOption.OnLoad;
                            image.EndInit(); // load the image from the stream
                        } // close the stream
                        SquareImageImg.Source = image;
                    }
                    else
                    {

                        CroquisUbicationTxBx.Text = string.Empty;
                    }

            }
        }

        public string SquareId
        {
            get
            {
                return SquareNameTxBx.Text;
            }
            set
            {
                SquareNameTxBx.Text = value;
            }

        }

        public string CommentSquare
        {
            get { return SquareCommentTxBx.Text; }
            set { SquareCommentTxBx.Text = value; }

        }

        public Model.Square SquareToRegister
        {
            get;
            set;

        }

        public ICollection<Model.Allotment> AllotmentsToRegister
        {
            get;
            set;

        }

        public void Update()
        {
            pFirstStepForRegisterSquare.UpdateData();
        }

        public string UbicationCroquisSquareToRegister
        {
            get;
            set;
        }

        public string SystemMessage
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                pInternal.NotifySystemMessage(value);
            }
        }

        public string ErrorMessage
        {
            get {
                throw new NotImplementedException();
            }
            set
            {
                pInternal.NotifyErrorMessage(value);            
            }
        }

        public void ChargeDataToBasic()
        {
            pFirstStepForRegisterSquare.ChargeDataMedicineProduct();
        }

        public void GoNextPage()
        {
            pInternal.GoStepTwo();
        }

        public void GoBackPage()
        {
            
        }


    }
}
